<?php
!defined('M_P') && exit('Forbidden');
require_once(R_P.'require/element.class.php');// Load Element Class
$element = new Element();
InitGP(array('cateid'),'GP',2);
$cateid>0 && ObHeader("cate.php?cateid=$cateid");
// forum info
$forumdb = $showsub = $pwTPost = array();
$first_notice = reset($notice_A);
$query  = $db->query("SELECT f.fid,f.childid,f.fup,f.logo,f.descrip,f.forumadmin,f.across,f.allowhtm,f.password,f.allowvisit,f.showsub,fd.tpost,fd.topic,fd.article,fd.subtopic,fd.top1,fd.lastpost FROM pw_forums f LEFT JOIN pw_forumdata fd USING(fid) WHERE f.ifsub='0' AND f.cms!=1 AND f.f_type!='hidden' ORDER BY f.vieworder");
while ($forums = $db->fetch_array($query)) {
	$forums['name'] = $forum[$forums['fid']]['name'];
	$forums['type'] = $forum[$forums['fid']]['type'];
	if ($forums['type'] === 'category') {
		$forums['admin'] = '';
	} elseif ($forums['type'] === 'forum') {
		$forums['stripname'] = strip_tags($forums['name']);
		if ($forums['showsub'] && $forums['childid']) {
			$showsub[$forums['fid']] = '';
		}
		$forums['topics'] = $forums['topic']+$forums['subtopic'];
		if ($db_topped) {
			$forums['topics'] += $forums['top1'];
			$forums['article'] += $forums['top1'];
		}
		$article += $forums['article'];
		$topics += $forums['topics'];
		$tposts += $forums['tpost'];
		$forums['au'] = $forums['admin'] = '';
		$pwTPost[$forums['fup']] += $forums['tpost'];
		$forumdb[$forums['fup']][] = array('fid' => $forums['fid'],'name' => $forums['name'],'stripname' => $forums['stripname'],'topics' => $forums['topics'],'article' => $forums['article'],'tpost' => $forums['tpost'],'admin' => $forums['admin'],'pic' => $forums['pic'],'logo' => $forums['logo'],'descrip' => $forums['descrip'],'au' => $forums['au'],'ft' => $forums['ft'],'t' => $forums['t'],'newtitle' => $forums['newtitle']);
	}
}
$db->free_result($query);

//版块内容调用
@include_once(Pcv(D_P.'data/bbscache/mode_index_forum_'.$db_mode.'_config.php'));
@include_once(Pcv(D_P.'data/bbscache/mode_'.$db_mode.'_index_forum.php'));
$updatetime	= 600;
$isupdated	= 0;
!is_array($index_forum_config) && $index_forum_config = array();
foreach($index_forum_config as $key => $value){
	foreach ($value as $k => $v) {
		if (empty($index_forum[$key][$v]['new']) || ($index_forum[$key][$v]['updatetime'] && ($timestamp - $index_forum[$key][$v]['updatetime'] > $updatetime)) && $isupdated == 0){
			$newsubjectdbs = $newpicdbs = array();
			//版块新帖调用
			$subject_show_num = count($value) == 3 ? 7 : 10;
			$newsubjectdb = $element -> newSubject('',$v,$subject_show_num);
			foreach ($newsubjectdb as $subjects) {
				$newsubjectdbs[] = array(
					'tid' => $subjects['addition']['tid'],
					'title' => substrs($subjects['title'],40),
					'authorid' => $subjects['addition']['authorid'],
					'author' => $subjects['addition']['author']
				);
			}
			$index_forum[$key][$v]['new'] = $newsubjectdbs;

			//版块新图调用
			$pic_show_num = count($value) == 2 ? 2 : (count($value) == 1 ? 4 : 1);
			$newpicdb = $element->newPic('',$v,$pic_show_num);
			foreach ($newpicdb as $pics) {
				$newpicdbs[] = array(
					'url' => $pics['url'],
					'title' => substrs($pics['title'],40),
					'image' => $pics['image'],
					'replies' => $pics['addition']['replies'],
					'content' => $pics['value']
				);
			}
			$index_forum[$key][$v]['newpic'] = $newpicdbs;

			$index_forum[$key][$v]['updatetime'] = $timestamp;
			$isupdated = $key;
			$ifwriteover = 1;
		}
	}
}
if ($ifwriteover == 1) {
	writeover(Pcv(D_P.'data/bbscache/mode_'.$db_mode.'_index_forum.php'),"<?php\r\n\$index_forum=".pw_var_export($index_forum).";\r\n?>");
}
$index_forum && krsort($index_forum);
?>